import pandas as pd #导入pandas

# df = pd.read_excel("../datafile/中超赛事表.xlsx")
# print(df)

#Series
# data = ["李光地", "张红云", "王鹏"]
# # s = pd.Series(data=data)#位置索引
# s = pd.Series(data=data,index=[1, 2, 3])
#
# print(s)
# print(type(s))

# data = [90, 98, 79]
# s = pd.Series(data=data,index=["张三", "李四", "王五"])#标签索引
# # print(s)
# # print(s["张三"])
# print(s[["张三", "李四"]])


# data = ["李光地", "张红云", "王鹏", "昆山","王哦"]
# # s = pd.Series(data=data)#位置索引
# s = pd.Series(data=data,index=[1, 2, 3, 4, 5])
# print(s[0:2:1])

# data = [90, 98, 79]
# index = ["张三", "李四", "王五"]
# s = pd.Series(data=data,index=index)#标签索引
# # print(s)
# # print(s.index)
# # print(list(s.index))
# # print(s.values)
# print(type(s.values))

#DateFrame
# data = [['小太阳', 320.9, 100],['鼠标', 150.3, 50],['小刀',1.5, 200]]
# columns = ['名称', '单价', '数量']
# index = []
# df = pd.DataFrame(data = data,columns = columns)
# print(df)

# data = {
#     '名称': ['小太阳', '鼠标', '小刀', '铅笔'],
#     '单价': [320.9, 150.3, 1.5, 1],
#     '数量': [100, 50, 200, 500],
#     '公司名称': '东门超市'
# }
# df = pd.DataFrame(data=data)
# # print(df)
# # print("查看所有的元素值:\n", df.values)
# # print("查看所有的元素类型:\n", df.dtypes)
# # print("查看所有的行名称:\n", list(df.index))
# # df.index = [1, 2, 3, 4]
# # print(df)
#
# # print("查看列索引:\n", list(df.columns))
# df.columns = ['商品名称', '最新单价', '实时数量', '公司名称']
# # print("查看列索引:\n", list(df.columns))
# pd.set_option('display.unicode.east_asian_width', True)
# # print(df.T)#行列转换
# # print(df)
# # print(df.head(2))
# # print(df.tail(1))
# # print('行',df.shape[0], '列',df.shape[1])
# print('查看索引、数据类型、内存信息\n',df.info)
#

# data = {
#     '名称': ['小太阳', '鼠标', '小刀', '铅笔'],
#     '单价': [320.9, 150.3, 1.5, 1],
#     '数量': [100, 50, 200, 500],
#     '公司名称': '东门超市'
# }
# df = pd.DataFrame(data=data)
#
# # print(df.describe())
# print(df.max())
# print(df.min())

# url = 'https://www.espn.com/nba/salaries'
# df =pd.DataFrame()
# df = df._append(pd.read_html(url,header=0))
# print(df)
# df.to_csv('nba.csv',index=False)

# data = [[45, 65, 100], [56, 45, 50], [67, 67, 67]]
# index = ['张三', '李四', '王五']
# columns = ['数学', '语文', '英语']
#
# df = pd.DataFrame(data=data, index=index, columns=columns)
# pd.set_option('display.unicode.east_asian_width', True)
# print(df)
#提取行数据
# print(df.loc['张三'])#行索引名称
# print(df.iloc[0])#行索引编号
# print(df.loc['张三', '王五'])#行索引名称
# print(df.iloc[[0,2]])

#提取列数据
# print(df[['数学', '英语']])
# print(df.loc[:, ['数学', '英语']])
# print(df.iloc[:, [0,2]])
# print(df.loc[:, '语文':])
# print(df.iloc[:, 1:])

# print(df.loc[df['语文'] >= 60])#条件判断
# print(df.loc[(df['语文'] >= 60) & (df['数学'] >= 60)])

#数据的增加和删除
# data = [[45, 65, 100], [56, 45, 50], [67, 67, 67]]
# index = ['张三', '李四', '王五']
# columns = ['数学', '语文', '英语']
#
# df = pd.DataFrame(data=data, index=index, columns=columns)
# pd.set_option('display.unicode.east_asian_width', True)

# df['政治'] = [90,89,100]#直接增加
# print(df)

# df.loc[:, '化学'] =[100, 30, 98]#指定位置
# print(df)
# lst = [100, 90, 99]
# df.insert(1,'历史',lst)#索引位置
# print(df)

# df.loc['陈六'] = [56, 67, 90]#单行增加
# print(df)

#新建datafrom
# new_df = pd.DataFrame(
#     data = {'数学':[67,69],
#             '语文':[58,78],
#             '英语':[100,99]},
#     index=['张丽丽', '王一一']
# )
# df =  df._append(new_df)
# print(df)
# df.columns = ['数学（上）', '语文（上）', '英语（上）']
#
# df.rename(columns={'数学（上）':'数学（下）',  '语文（上）':'语文（下）', '英语（上）':'英语（下）'},inplace=True)

# df.index = list('123')
# df.rename({'1':'一一',  '3':'三三'},inplace=True,axis = 0)
#
# print(df)

# data = [[45, 65, 100], [56, 45, 50], [67, 67, 67]]
# index = ['张三', '李四', '王五']
# columns = ['数学', '语文', '英语']
#
# df = pd.DataFrame(data=data, index=index, columns=columns)
# pd.set_option('display.unicode.east_asian_width', True)

#修改一整行
# df.loc['张三'] = [100, 100, 99]
# print(df)

# df.iloc[0,:] = [90, 90, 99]
# print(df)

# df.loc[:,'数学'] = [70, 80, 99]
# df.iloc[:,0] = [80, 80, 80]

# df.loc['李四','语文'] = 100
# df.iloc[1, 1] = 30

# df.drop(['数学'],axis=1,inplace=True)
# df.drop(columns='数学',inplace=True)
# df.drop(labels='数学',axis=1,inplace=True)

# df.drop(['张三'],axis=0,inplace=True)
# df.drop(index='张三',inplace=True)
# df.drop(labels='张三',axis=0,inplace=True)
# print(df)

data = [[45, 65, 100], [56, 45, 50], [67, 67, 67]]
index = ['张三', '李四', '王五']
columns = ['数学', '语文', '英语']

df = pd.DataFrame(data=data, index=index, columns=columns)
pd.set_option('display.unicode.east_asian_width', True)

df.drop(df[df['数学'] < 60].index[1], inplace=True)
print(df)